package com.betterjr.modules.risk.loan.data;

import java.util.ArrayList;
import java.util.List;

import com.betterjr.common.utils.Collections3;
import com.betterjr.modules.risk.loan.dao.FillAgreementInterfaces;
import com.betterjr.modules.risk.loan.entity.LoanProjectElcAgreement;
import com.betterjr.modules.risk.loan.entity.LoanProjectRelation;

public class FillAgreementFactory {

    private static List<FillAgreementInterfaces> agreementImpl = new ArrayList<>(16);

    static {
        agreementImpl.add(new AccountRegulatoryFillAgreement());
        agreementImpl.add(new DataConfirmFillAgreement());
        agreementImpl.add(new OthersFillAgreement());
        agreementImpl.add(new PlatformServiceFillAgreement());

    }

    public static void addAgreement(FillAgreementInterfaces agreement) {

        if (agreementImpl != null && !agreementImpl.contains(agreement)) {
            agreementImpl.add(agreement);
        }
    }

    public static void removeaddAgreement(FillAgreementInterfaces agreement) {

        if (agreementImpl != null && !agreementImpl.contains(agreement)) {
            agreementImpl.remove(agreement);
        }

    }

    public static void invoke(LoanProjectRelation anLoan, List<LoanProjectElcAgreement> agreements) {

        if (anLoan != null && !Collections3.isEmpty(agreements)) {

            for (LoanProjectElcAgreement agreement : agreements) {
                for (FillAgreementInterfaces fillAgreement : agreementImpl) {
                    if (fillAgreement.fillAgreement(anLoan, agreement)) break;
                }
            }

        }

    }

}
